home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / mfbfillarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  7.6 KB  |  344 lines

  1. /************************************************************
  2. Copyright 1989 by The Massachusetts Institute of Technology
  3.  
  4. Permission to use, copy, modify, and distribute this
  5. software and its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting
  9. documentation, and that the name of MIT not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific prior written permission.
  12. M.I.T. makes no representation about the suitability of
  13. this software for any purpose. It is provided "as is"
  14. without any express or implied warranty.
  15.  
  16. ********************************************************/
  17.  
  18. /* $XConsortium: mfbfillarc.c,v 5.6 89/11/24 18:07:50 rws Exp $ */
  19.  
  20. #include "X.h"
  21. #include "Xprotostr.h"
  22. #include "miscstruct.h"
  23. #include "gcstruct.h"
  24. #include "pixmapstr.h"
  25. #include "scrnintstr.h"
  26. #include "mfb.h"
  27. #include "maskbits.h"
  28. #include "mifillarc.h"
  29.  
  30. extern void miPolyFillArc();
  31.  
  32. static void
  33. mfbFillEllipseSolid(pDraw, arc, rop)
  34.     DrawablePtr pDraw;
  35.     xArc *arc;
  36.     register int rop;
  37. {
  38.     int iscircle;
  39.     int x, y, e, ex;
  40.     int yk, xk, ym, xm, dx, dy, xorg, yorg;
  41.     register int slw;
  42.     miFillArcRec info;
  43.     int *addrlt, *addrlb;
  44.     register int *addrl;
  45.     register int n;
  46.     int nlwidth;
  47.     register int xpos;
  48.     int startmask, endmask, nlmiddle;
  49.  
  50.     if (pDraw->type == DRAWABLE_WINDOW)
  51.     {
  52.     addrlt = (int *)
  53.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  54.     nlwidth = (int)
  55.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  56.     }
  57.     else
  58.     {
  59.     addrlt = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  60.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  61.     }
  62.     miFillArcSetup(arc, &info);
  63.     MIFILLARCSETUP();
  64.     xorg += pDraw->x;
  65.     yorg += pDraw->y;
  66.     addrlb = addrlt;
  67.     addrlt += nlwidth * (yorg - y);
  68.     addrlb += nlwidth * (yorg + y + dy);
  69.     iscircle = (arc->width == arc->height);
  70.     while (y)
  71.     {
  72.     addrlt += nlwidth;
  73.     addrlb -= nlwidth;
  74.     if (iscircle)
  75.     {
  76.         MIFILLCIRCSTEP(slw);
  77.     }
  78.     else
  79.     {
  80.         MIFILLELLSTEP(slw);
  81.         if (!slw)
  82.         continue;
  83.     }
  84.     xpos = xorg - x;
  85.     addrl = addrlt + (xpos >> 5);
  86.     if (((xpos & 0x1f) + slw) < 32)
  87.     {
  88.         maskpartialbits(xpos, slw, startmask);
  89.         if (rop == RROP_BLACK)
  90.         *addrl &= ~startmask;
  91.         else if (rop == RROP_WHITE)
  92.         *addrl |= startmask;
  93.         else
  94.         *addrl ^= startmask;
  95.         if (miFillArcLower(slw))
  96.         {
  97.         addrl = addrlb + (xpos >> 5);
  98.         if (rop == RROP_BLACK)
  99.             *addrl &= ~startmask;
  100.         else if (rop == RROP_WHITE)
  101.             *addrl |= startmask;
  102.         else
  103.             *addrl ^= startmask;
  104.         }
  105.         continue;
  106.     }
  107.     maskbits(xpos, slw, startmask, endmask, nlmiddle);
  108.     if (startmask)
  109.     {
  110.         if (rop == RROP_BLACK)
  111.         *addrl++ &= ~startmask;
  112.         else if (rop == RROP_WHITE)
  113.         *addrl++ |= startmask;
  114.         else
  115.         *addrl++ ^= startmask;
  116.     }
  117.     n = nlmiddle;
  118.     if (rop == RROP_BLACK)
  119.         while (n--)
  120.         *addrl++ = 0;
  121.     else if (rop == RROP_WHITE)
  122.         while (n--)
  123.         *addrl++ = ~0;
  124.     else
  125.         while (n--)
  126.         *addrl++ ^= ~0;
  127.     if (endmask)
  128.     {
  129.         if (rop == RROP_BLACK)
  130.         *addrl &= ~endmask;
  131.         else if (rop == RROP_WHITE)
  132.         *addrl |= endmask;
  133.         else
  134.         *addrl ^= endmask;
  135.     }
  136.     if (!miFillArcLower(slw))
  137.         continue;
  138.     addrl = addrlb + (xpos >> 5);
  139.     if (startmask)
  140.     {
  141.         if (rop == RROP_BLACK)
  142.         *addrl++ &= ~startmask;
  143.         else if (rop == RROP_WHITE)
  144.         *addrl++ |= startmask;
  145.         else
  146.         *addrl++ ^= startmask;
  147.     }
  148.     n = nlmiddle;
  149.     if (rop == RROP_BLACK)
  150.         while (n--)
  151.         *addrl++ = 0;
  152.     else if (rop == RROP_WHITE)
  153.         while (n--)
  154.         *addrl++ = ~0;
  155.     else
  156.         while (n--)
  157.         *addrl++ ^= ~0;
  158.     if (endmask)
  159.     {
  160.         if (rop == RROP_BLACK)
  161.         *addrl &= ~endmask;
  162.         else if (rop == RROP_WHITE)
  163.         *addrl |= endmask;
  164.         else
  165.         *addrl ^= endmask;
  166.     }
  167.     }
  168. }
  169.  
  170. #define FILLSPAN(xl,xr,addr) \
  171.     if (xr >= xl) \
  172.     { \
  173.     width = xr - xl + 1; \
  174.     addrl = addr + (xl >> 5); \
  175.     if (((xl & 0x1f) + width) < 32) \
  176.     { \
  177.         maskpartialbits(xl, width, startmask); \
  178.         if (rop == RROP_BLACK) \
  179.         *addrl &= ~startmask; \
  180.         else if (rop == RROP_WHITE) \
  181.         *addrl |= startmask; \
  182.         else \
  183.         *addrl ^= startmask; \
  184.     } \
  185.     else \
  186.     { \
  187.         maskbits(xl, width, startmask, endmask, nlmiddle); \
  188.         if (startmask) \
  189.         { \
  190.         if (rop == RROP_BLACK) \
  191.             *addrl++ &= ~startmask; \
  192.         else if (rop == RROP_WHITE) \
  193.             *addrl++ |= startmask; \
  194.         else \
  195.             *addrl++ ^= startmask; \
  196.         } \
  197.         n = nlmiddle; \
  198.         if (rop == RROP_BLACK) \
  199.         while (n--) \
  200.             *addrl++ = 0; \
  201.         else if (rop == RROP_WHITE) \
  202.         while (n--) \
  203.             *addrl++ = ~0; \
  204.         else \
  205.         while (n--) \
  206.             *addrl++ ^= ~0; \
  207.         if (endmask) \
  208.         { \
  209.         if (rop == RROP_BLACK) \
  210.             *addrl &= ~endmask; \
  211.         else if (rop == RROP_WHITE) \
  212.             *addrl |= endmask; \
  213.         else \
  214.             *addrl ^= endmask; \
  215.         } \
  216.     } \
  217.     }
  218.  
  219. #define FILLSLICESPANS(flip,addr) \
  220.     if (!flip) \
  221.     { \
  222.     FILLSPAN(xl, xr, addr); \
  223.     } \
  224.     else \
  225.     { \
  226.     xc = xorg - x; \
  227.     FILLSPAN(xc, xr, addr); \
  228.     xc += slw - 1; \
  229.     FILLSPAN(xl, xc, addr); \
  230.     }
  231.  
  232. static void
  233. mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop)
  234.     DrawablePtr pDraw;
  235.     GCPtr pGC;
  236.     xArc *arc;
  237.     register int rop;
  238. {
  239.     register int *addrl;
  240.     register int n;
  241.     int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
  242.     register int x, y, e, ex;
  243.     miFillArcRec info;
  244.     miArcSliceRec slice;
  245.     int xl, xr, xc;
  246.     int iscircle;
  247.     int *addrlt, *addrlb;
  248.     int nlwidth;
  249.     int width;
  250.     int startmask, endmask, nlmiddle;
  251.  
  252.     if (pDraw->type == DRAWABLE_WINDOW)
  253.     {
  254.     addrlt = (int *)
  255.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  256.     nlwidth = (int)
  257.            (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  258.     }
  259.     else
  260.     {
  261.     addrlt = (int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  262.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  263.     }
  264.     miFillArcSetup(arc, &info);
  265.     miFillArcSliceSetup(arc, &slice, pGC);
  266.     MIFILLARCSETUP();
  267.     iscircle = (arc->width == arc->height);
  268.     xorg += pDraw->x;
  269.     yorg += pDraw->y;
  270.     addrlb = addrlt;
  271.     addrlt += nlwidth * (yorg - y);
  272.     addrlb += nlwidth * (yorg + y + dy);
  273.     slice.edge1.x += pDraw->x;
  274.     slice.edge2.x += pDraw->x;
  275.     while (y > 0)
  276.     {
  277.     addrlt += nlwidth;
  278.     addrlb -= nlwidth;
  279.     if (iscircle)
  280.     {
  281.         MIFILLCIRCSTEP(slw);
  282.     }
  283.     else
  284.     {
  285.         MIFILLELLSTEP(slw);
  286.     }
  287.     MIARCSLICESTEP(slice.edge1);
  288.     MIARCSLICESTEP(slice.edge2);
  289.     if (miFillSliceUpper(slice))
  290.     {
  291.         MIARCSLICEUPPER(xl, xr, slice, slw);
  292.         FILLSLICESPANS(slice.flip_top, addrlt);
  293.     }
  294.     if (miFillSliceLower(slice))
  295.     {
  296.         MIARCSLICELOWER(xl, xr, slice, slw);
  297.         FILLSLICESPANS(slice.flip_bot, addrlb);
  298.     }
  299.     }
  300. }
  301.  
  302. void
  303. mfbPolyFillArcSolid(pDraw, pGC, narcs, parcs)
  304.     register DrawablePtr pDraw;
  305.     GCPtr    pGC;
  306.     int        narcs;
  307.     xArc    *parcs;
  308. {
  309.     mfbPrivGC *priv;
  310.     register xArc *arc;
  311.     register int i;
  312.     BoxRec box;
  313.     RegionPtr cclip;
  314.     int rop;
  315.  
  316.     priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  317.     rop = priv->rop;
  318.     if ((rop == RROP_NOP) || !(pGC->planemask & 1))
  319.     return;
  320.     cclip = priv->pCompositeClip;
  321.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  322.     {
  323.     if (miFillArcEmpty(arc))
  324.         continue;
  325.     if (miCanFillArc(arc))
  326.     {
  327.         box.x1 = arc->x + pDraw->x;
  328.         box.y1 = arc->y + pDraw->y;
  329.         box.x2 = box.x1 + (int)arc->width + 1;
  330.         box.y2 = box.y1 + (int)arc->height + 1;
  331.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  332.         {
  333.         if ((arc->angle2 >= FULLCIRCLE) ||
  334.             (arc->angle2 <= -FULLCIRCLE))
  335.             mfbFillEllipseSolid(pDraw, arc, rop);
  336.         else
  337.             mfbFillArcSliceSolidCopy(pDraw, pGC, arc, rop);
  338.         continue;
  339.         }
  340.     }
  341.     miPolyFillArc(pDraw, pGC, 1, arc);
  342.     }
  343. }
  344.